﻿/// <reference path="../Ext/ext-base-debug-w-comments.js" />
/// <reference path="../Ext/ext-all-debug.js" />
Ext.namespace('Yame');

Yame.IconCombo = function (config) {
    Yame.IconCombo.superclass.constructor.call(this, config);
    this.tpl = config.tpl ||
            '<tpl for="."><div class="x-combo-list-item">'
           + '<div class="{' + this.iconClsField + '} x-icon-combo-icon">'
           + '{' + this.displayField + '}</div>'
           + '</div></tpl>';

    this.on('render', function () {
        var wrap = this.el.up('div.x-form-field-wrap');
        wrap.applyStyles({ position: 'relative' });
        this.el.addClass('x-icon-combo-input');
        this.flag = Ext.DomHelper.append(wrap, {
            tag: 'div', style: 'position:absolute'
        });
    }, this);
};

Ext.extend(Yame.IconCombo, Ext.form.ComboBox, {
    setIconCls: function () {
        var rec = this.store.query(this.valueField, this.getValue()).itemAt(0);
        if (rec) {
            this.flag.className = 'x-icon-combo-icon ' + rec.get(this.iconClsField);
        }
    },
    setValue: function (value) {
        Yame.IconCombo.superclass.setValue.call(this, value);
        this.setIconCls();
    }
});

Ext.reg('iconcombo', Yame.IconCombo);